﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Data;
using System.Data.OleDb;

/// <summary>
///ExcelHelper 的摘要说明
/// </summary>
public class ExcelHelper
{
	public ExcelHelper(){}

    public static DataTable getFridtTable(string filepath) {
        DataSet ds = new DataSet();
        string conn = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " + filepath + ";Extended Properties=Excel 8.0;";
        string sql = "select * from [Sheet1$]";
        using (OleDbCommand cmd = new OleDbCommand(sql, new OleDbConnection(conn))) {
            OleDbDataAdapter ad = new OleDbDataAdapter(cmd);
            ad.Fill(ds);
        }
        return ds.Tables[0];

        //DataTable sheetNames = conn.GetOleDbSchemaTable  
        //(System.Data.OleDb.OleDbSchemaGuid.Tables, new object[] { null, null, null, "TABLE" });  
        //conn.Close();  
        //foreach (DataRow dr in sheetNames.Rows)  {  
        //    al.Add(dr[2]);  
        //}  
        //return dt;  
    }  

}